<template>
  <Home
    v-if="loginstate == 1"
    :jwttoken="jwttoken"
    v-on:loginstate1="abc"
  ></Home>
  <Login v-else></Login>
</template>

<script>
import Home from "./components/Home.vue";
import Login from "./components/Login.vue";
import { ElMessage } from "element-plus";
export default {
  name: "App",
  components: {
    // HelloWorld
    Home,
    Login,
  },
  data() {
    return {
      loginstate: 1,
      jwttoken: "",
    };
  },
  watch: {
    loginstate(newval) {
      let that=this
      if(newval==-1){
        ElMessage.warning({
            message: '登陆超时，请重新登陆',
            type: 'warning'
          });
        setTimeout(() => {
          that.loginstate = newval;
        }, 2000);
        this.loginstate = newval;
      }
      console.log(newval)
    },
    jwttoken(newVal) {
      localStorage.setItem("maisheng-jwttoken", newVal);
      this.loginstate = 1;
    },
  },
  created: function () {
    let jwttoken = localStorage.getItem("maisheng-jwttoken");
    if (!jwttoken) {
      this.loginstate = -1;
    } else {
      this.jwttoken = jwttoken;
    }
    this.$emit("jwttoken", jwttoken);
  },
  methods: {
    abc: function (dat) {
      this.loginstate=dat
    },
  },
};
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
